package _租车系统;

import java.util.Objects;

public class CarRentalCompanies {
    String name;
    String dianhua;
    Car[] ar = new Car[20];
    ZuCheRenXinxi[] arr = new ZuCheRenXinxi[20];

    public CarRentalCompanies() {
        ar[0] = new TheCar("皖A9654", "大众", 200, 6, 0, 0, true);
        ar[1] = new TheCar("皖C9655", "奔驰", 500, 5, 0, 0, false);
        ar[2] = new TheCar("皖C9656", "吉利", 500, 5, 0, 0, false);
        ar[3] = new TheCar("皖C9657", "奥迪", 500, 5, 0, 0, false);
        ar[4] = new PassengerCar("皖C9658", "金杯", 900, 30, 0, 0, false);

    }

    public void chakan() {
        for (int a = 0; a < ar.length; a++) {
            if (ar[a] != null) {
                String x = ar[a].state ? "已出租" : "未出租";
                System.out.println("车名:" + ar[a].pinpai + "\t车牌号:" + ar[a].chepai + "\t租金:" + ar[a].zujin + "\t座位:" + ar[a].zuowei + "\t状态:" + x + "\t出租天数:" + ar[a].day + "\t" + ar[a].feiyong);
            }
        }
    }

    public boolean zuche(String chepai, int day, String name, String dianhua) {
        for (int a = 0; a < ar.length; a++) {
            if (ar[a] != null) {
                if (ar[a].chepai.equals(chepai) && ar[a].state) {
                    System.out.println("已出租");
                    return false;
                } else if (ar[a].chepai.equals(chepai) && !ar[a].state) {
                    ar[a].state = true;
                    ar[a].day = day;
                    ar[a].feiyong = ar[a].feiyong();
                    System.out.println("需缴纳费用:" + ar[a].feiyong);
                    System.out.println(ar[a].feiyong);
                    System.out.println("租车成功");
                    for (int x = 0; x < arr.length; x++) {
                        if (arr[x] == null) {
                            arr[x] = new ZuCheRenXinxi();
                            arr[x].name = name;
                            arr[x].dianhua = dianhua;
                            arr[x].pinpai = ar[a].pinpai;
                            arr[x].chepai = ar[a].chepai;
                            arr[x].day = ar[a].day;
                            arr[x].feiyong = ar[a].feiyong;
                            return true;
                        }
                    }
                }
            }
        }
        System.out.println("查无此车");
        return false;
    }

    public void zucheren() {
        for (int a = 0; a < arr.length; a++) {
            if (arr[a] != null) {
                System.out.println("姓名:" + arr[a].name + "\n联系电话:" + arr[a].dianhua + "车名:" + arr[a].pinpai + "\t车牌号:" + arr[a].chepai + "\t出租天数:" + arr[a].day + "\t" + arr[a].feiyong);
            } else {
                return;
            }
        }
    }

    public boolean huanche(String chepai) {
        for (int a = 0; a < ar.length; a++) {
            if (ar[a] != null) {
                if (Objects.equals(ar[a].chepai, chepai)) {
                    if (ar[a].state) {
                        ar[a].state = false;
                        return true;
                    } else {
                        System.out.println("此车未出租");
                        return false;
                    }
                }
            }
        }
        return false;
    }

    public boolean baofei(String chepai) {
        for (int a = 0; a < ar.length; a++) {
            if (Objects.equals(ar[a].chepai, chepai)) {
                if (ar[a].state) {
                    System.out.println("车辆正在出租无法报废");
                    return false;
                } else if (!ar[a].state) {
                    ar[a] = null;
                    return true;
                }
            }
        }
        return false;
    }

    public boolean maijin(String car, String pinpai, String chepai, int zujin, int jizuo) {
        for (int a = 0; a < ar.length; a++) {
            if (ar[a] == null) {
                if (Objects.equals(car, "小轿车")) {
                    ar[a] = new TheCar();
                    ar[a].pinpai = pinpai;
                    ar[a].chepai = chepai;
                    ar[a].zujin = zujin;
                    ar[a].zuowei = jizuo;
                    ar[a].state = false;
                    return true;
                } else {
                    if (Objects.equals(car, "客车")) {
                        ar[a] = new PassengerCar();
                        ar[a].pinpai = pinpai;
                        ar[a].chepai = chepai;
                        ar[a].zujin = zujin;
                        ar[a].zuowei = jizuo;
                        ar[a].state = false;
                        return true;
                    }
                }
            }
        }
        return false;
    }
}